package com.peng.leetcode.tree;

/**
 * IsSymmetric
 * 剑指 Offer 28. 对称的二叉树
 * https://leetcode.cn/problems/dui-cheng-de-er-cha-shu-lcof/
 * <p>
 * Created on 2022/11/27
 *
 * @author lupeng
 */
public class IsSymmetric {

    public boolean isSymmetric(TreeNode root) {
        return check(root, root);
    }

    private boolean check(TreeNode n1, TreeNode n2) {
        if (n1 == null && n2 == null) {
            return true;
        }
        if (n1 == null || n2 == null) {
            return false;
        }
        if (n1.val != n2.val) {
            return false;
        }
        return check(n1.left, n2.right) && check(n1.right, n2.left);
    }

}
